#ifndef BSPLINECUBSURF_H_
#define BSPLINECUBSURF_H_

#include <GL/glew.h>
#include <GL/glut.h>
#include <glm/glm.hpp>

#include <string.h>
#include <vector>

#define DETAILBSPLINESURF 10
#define TAMBSPLINE 51
#define TAMPATCHBSPLINE 4

using std::vector;

class BSplineCubSurf{
	public:
		BSplineCubSurf();
		BSplineCubSurf(GLfloat ctrlpoints[TAMPATCHBSPLINE][TAMPATCHBSPLINE][3]);
		void drawSurface(glm::mat4 mat);
		void drawControlPoints();
		void drawNormals(glm::mat4);

	private:
		GLfloat controlPoints[TAMPATCHBSPLINE][TAMPATCHBSPLINE][3];
		float surface[TAMBSPLINE][TAMBSPLINE][3];
		float normals[TAMBSPLINE][TAMBSPLINE][3];

		void calculateSurface();
		void calculateNormals();
		void calculateNormalForMiddlePoint(size_t x,size_t y,float h);
		void calculateNormalForPositBorderPoint(size_t x,size_t y,float h);
		void calculateNormalForNegBorderPoint(size_t x,size_t y,float h);
		float baseBSpline(size_t n,size_t j,float t);
};

#endif
